package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.vo.ZhcaMesVo;
import com.ruoyi.system.bo.ZhcaMesQueryBo;
import com.ruoyi.system.bo.ZhcaMesAddBo;
import com.ruoyi.system.bo.ZhcaMesEditBo;
import com.ruoyi.system.service.IZhcaMesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 首页信息栏位Controller
 *
 * @author huaqihao
 * @date 2021-07-25
 */
@Validated
@Api(value = "首页信息栏位控制器", tags = {"首页信息栏位管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/mes")
public class ZhcaMesController extends BaseController {

    private final IZhcaMesService iZhcaMesService;

    /**
     * 查询首页信息栏位列表
     */
    @ApiOperation("查询首页信息栏位列表")
   // @PreAuthorize("@ss.hasPermi('system:mes:list')")
    @GetMapping("/list")
    public TableDataInfo<ZhcaMesVo> list(@Validated ZhcaMesQueryBo bo) {
        return iZhcaMesService.queryPageList(bo);
    }

    /**
     * 导出首页信息栏位列表
     */
    @ApiOperation("导出首页信息栏位列表")
    @PreAuthorize("@ss.hasPermi('system:mes:export')")
    @Log(title = "首页信息栏位", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<ZhcaMesVo> export(@Validated ZhcaMesQueryBo bo) {
        List<ZhcaMesVo> list = iZhcaMesService.queryList(bo);
        ExcelUtil<ZhcaMesVo> util = new ExcelUtil<ZhcaMesVo>(ZhcaMesVo.class);
        return util.exportExcel(list, "首页信息栏位");
    }

    /**
     * 获取首页信息栏位详细信息
     */
    @ApiOperation("获取首页信息栏位详细信息")
    @PreAuthorize("@ss.hasPermi('system:mes:query')")
    @GetMapping("/{id}")
    public AjaxResult<ZhcaMesVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iZhcaMesService.queryById(id));
    }

    /**
     * 新增首页信息栏位
     */
    @ApiOperation("新增首页信息栏位")
    @PreAuthorize("@ss.hasPermi('system:mes:add')")
    @Log(title = "首页信息栏位", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody ZhcaMesAddBo bo) {
        return toAjax(iZhcaMesService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改首页信息栏位
     */
    @ApiOperation("修改首页信息栏位")
    @PreAuthorize("@ss.hasPermi('system:mes:edit')")
    @Log(title = "首页信息栏位", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody ZhcaMesEditBo bo) {
        return toAjax(iZhcaMesService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除首页信息栏位
     */
    @ApiOperation("删除首页信息栏位")
    @PreAuthorize("@ss.hasPermi('system:mes:remove')")
    @Log(title = "首页信息栏位" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iZhcaMesService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
